package _2025_5_9;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class HTTPClient {
    private Socket socket;
    private String IP;
    private int port;

    public HTTPClient(String IP,int port) throws IOException {
        this.IP=IP;
        this.port=port;
        socket=new Socket(IP,port);
    }

    public String get(String url) throws IOException {
        //创建StringBUlider发送内容
        StringBuilder request=new StringBuilder();
        request.append("GET:"+url+"\n");
        request.append("IP:"+IP+" port:"+port+"\n");
        request.append("\n");
        //发送数据
        OutputStream outputStream=socket.getOutputStream();
        outputStream.write(request.toString().getBytes());

        //输出响应
        InputStream inputStream=socket.getInputStream();
        byte[] buffer=new byte[1024*10242];
        int n= inputStream.read(buffer);

        return new String(buffer,0,n,"utf-8");
    }


}
